<div class="modal fade bs-modal-md" id="modelContent">
	<div class="modal-dialog modal-md">
		<div class="modal-content"></div>
	</div>
</div>
<div class="portlet box green">
	<div class="portlet-title">
		<div class="caption">
			<i class="fa fa-search"></i>查询内容
		</div>
		<div class="tools">
			<a href="javascript:;" class="collapse right" data-original-title="" title=""> </a>
		</div>
		<div class="actions">
			<a href="javascript:;" class="btn white btn-sm ajax-search"><i class="fa fa-search"></i>查询 </a> 
			<a href="javascript:;" class="btn white btn-sm search-reset"><i class="fa fa-eraser"></i>清除 </a>
		</div>
	</div>
	<div class="portlet-body form" style="display: block;">
		<form action="/category/list" class="form-horizontal" method="get" id="searchForm" onsubmit="return false">
 			<div class="form-body">
				<div class="form-group ">
					<div class="col-md-6">
						<div class="col-md-4">
							<label class="control-label col-md-4">分类名称：</label>
							<div class="col-md-8">
								<input class="form-control" type="text" name="name"  value="$!name">
							</div>
						</div>
						<div class="col-md-4">
							<label class="control-label col-md-4">是否启用：</label>
							<div class="col-md-8">
								<select class="form-control" name="displays">
									<option value="">全部</option>
									<option #if($!displays == "true") selected="selected" #end   value="true">是</option>
									<option #if($!displays == "false") selected="selected" #end  value="false">否</option>
								</select>
							</div>
						</div>
						<div class="col-md-4">
							<label class="control-label col-md-4">关联类型：</label>
							<div class="col-md-8">
								<select class="form-control" name="attrGoupId" >
									<option value="">全部</option>
									#foreach($!attrGroup in $!attrGroupList)
										<option  #if($!attrGroup.id == $!attrGoupId) selected="selected" #end   value="$!attrGroup.id">$!attrGroup.name</option>
									#end
								</select>
							</div>
						</div>
					</div>
 					 <div class="col-md-5">
						 	<label class="control-label col-md-3">创建时间:</label>
						 	<div class="col-md-4">
						 		<input class="form-control" type="text" name="startTime" id="startTime" value="$!startTime" readonly>
								<i class="fa fa-calendar" style="position: absolute;right: 10px;top: 10px"></i>
						 	</div>
						 	<div class="col-md-1">～</div>
						 	<div class="col-md-4">
						 		<input class="form-control" type="text" name="endTime" id="endTime" value="$!endTime" readonly>
								<i class="fa fa-calendar" style="position: absolute;right: 10px;top: 10px"></i>
						 	</div>
					 </div>
				</div>
			</div>
		</form>
	</div>
</div>
<div class="portlet box green">
	<div class="portlet-title">
		<div class="caption"><i class="fa fa-cogs"></i>数据列表</div>
		<div class="tools"><a href="javascript:;" class="collapse" data-original-title="" title=""> </a></div>
		<div class="actions">
			<a href="#modelContent" thref="/category/add" class="btn white btn-sm ajax-model-get" code="category.add1" data-toggle="modal"><i class="fa fa-plus"></i> 新增一级分类 </a>
			<a class="btn white btn-sm  using-tg"  href="javascript:;" ><i class="fa fa-check-square-o"></i>启用</a>
			<a class="btn white btn-sm  forbid-tg"  href="javascript:;" > <i class="fa fa-square-o"></i>禁用</a>
			<a class="btn white btn-sm  "  href="javascript:;" onclick="jQuery('#tableCategory').treetable('expandAll'); return false;"><i class="fa fa-expand"></i>展开</a>
       	 	<a  class="btn white btn-sm  " href="javascript:;" onclick="jQuery('#tableCategory').treetable('collapseAll'); return false;"><i class="fa fa-compress"></i>折叠</a>
		</div>
	</div>
	<div class="portlet-body">
		<div >
			<table class="table table-striped table-bordered table-hover icheck-table" id="tableCategory">
				<thead>
					<tr>
						<th style="text-indent: 1em;"><input type="checkbox" class="icheck group-icheck" />货品类别</th>
<!-- 						<th>编码</th> -->
						<th>启用</th>
<!-- 						<th>前台显示</th> -->
						<th>货品类型</th>
						<th>创建时间</th>
						<th style="width: 24%;">操作</th>
					</tr>
				</thead>
				<tbody>
					#foreach ($item in $!categoryMap.resultDate) 
					<tr data-tt-id="$!item.id"  status='$!item.status' data-tt-parent-id="$!item.pid" id="$!item.id">
						<td style="vertical-align: middle !important;" class="branch"> 
							<input type="checkbox" name="checkboxes" class="icheck tric" value="$!item.id" />
							#if($!item.status == 1)
							#if($!item.image)
							<img alt="" src="$!imageUploadUrl$!item.image" width="25px" height="25px">
							#end
							<font style="color: red">$!item.name</font>
							#else
							#if($!item.image)
							<img alt="" src="$!imageUploadUrl$!item.image" width="25px" height="25px">
							#end
							<font>$!item.name</font>
							#end
						</td>
<!-- 						<td>$!item.id</td> -->
						<td>#if($!item.display == "true")
									<i class="fa fa-check font-yellow-gold"></i>
								#else
								 	<i class="fa fa-close font-red-flamingo"></i>
							 #end </td>
<!-- 						<td> -->
<!-- 							#if($!item.display)  -->
<!-- 		                    <span>是</span> -->
<!-- 		                    #else  -->
<!-- 		                    <span>否</span> -->
<!-- 		                    #end -->
<!-- 						</td> -->
						<td>
							 $!item.attrGoupName
						</td>
						<td>
							 $!item.createDate
						</td>
						<td>
							<a href="#modelContent" thref="/category/edit?id=$!item.id" class="btn green btn-outline btn-sm ajax-model-get" code="category.edit" data-toggle="modal">
							<i class="fa fa-edit"></i> 编辑</a>
    						#if(!$!item.attrGoupId && !$!item.brandIds && $!item.level != 3)
    							#set($child = $!child_hashMap.get($!item))
    							#if($child != "1")
								<a href="#modelContent" thref="/category/add?id=$!item.id" class="btn green btn-outline btn-sm ajax-model-get" code="category.add2" data-toggle="modal">
								<i class="fa fa-edit"></i>新增子类</a>
								#end
    						#end
    						
    							#set($del = $!del_hashMap.get($!item))
    						#if($del != "1")
    						<a href="javascript:;" thref="/category/delete?id=$!item.id" class="btn green btn-outline btn-sm ajax-delete" code="category.delete">
							<i class="fa fa-trash"></i>删除</a>
							#end
    					</td>
					</tr>
					#end
				</tbody>
				<tfoot>
					<tr>
						<td colspan="5">
						#foreach($category in $!cyList1)
							#set($num = $!categoryMap.get($!category.id))
							$!category.name分类$!num 个 ,
						#end
						</td>
					</tr>
				</tfoot>
			</table>
		</div>
	</div>
</div>
<!-- <script type="text/javascript" src="/assets/scripts/views-permission.js"></script> 
<script type="text/javascript" src="/assets/scripts/views-icheck.js"></script>
<script type="text/javascript" src="/assets/scripts/views-date.js" ></script> -->
<script type="text/javascript">

ComponentsSelect2.initWithSearch();

$("#tableCategory").treetable({
	indenterTemplate:"<span class ='indenter'> </ span>",
	expandable : true,
});



function recursion(tId,state){
	 var child_node= $("[data-tt-parent-id='"+tId+"' ]");
	 child_node.iCheck(state);
	 if(child_node.length != 0){
		 $.each(child_node,function(i,v){
			 var tpi = $(v).attr("data-tt-id");
			 recursion(tpi,state);
		 });
	 }
	 return;
}


$('.tric').on('ifChecked', function(){
	 var tId= $(this).val();
	 recursion(tId,"check");
})

$('.tric').on('ifUnchecked', function(){
	var tId= $(this).val();
	recursion(tId,"uncheck");
	
})

function getValues(){
	var array = new Array()
	var target= $("input[name='checkboxes']");
	//循环加入数组
	
		$.each(target,function(i,v){
			if(v.checked){
				array.push($(v).val());
			}
		});
	 	return array; 
 }
//启用
$(".using-tg").click(function(){
	var ciArray= getValues();
	if(ciArray.length == 0){
		return toastr.warning("请勾选要启用的分类");
	}
	
	bootbox.setLocale("zh_CN");
	bootbox.confirm("确定启用这些分类吗？", function(state) {
		if (state) {
			$.post("/category/editState", {
				 ciArray  : ciArray,
				 state :1
			}, function(result) {
				if (result.code == 0) {
					toastr.success(result.msg);
					pageContentBody.load("/category/list");
				} else {
					toastr.warning(result.msg);
				}
			}, "json");
		}
	});
});
//禁用
$(".forbid-tg").click(function(){
	var ciArray= getValues();
	if(ciArray.length == 0){
		return toastr.warning("请勾选要禁用的分类");
	}
	
	bootbox.setLocale("zh_CN");
	bootbox.confirm("确定禁用这些分类吗？", function(state) {
		if (state) {
			$.post("/category/editState", {
				 ciArray  : ciArray,
				 state :0
			}, function(result) {
				if (result.code == 0) {
					toastr.success(result.msg);
					pageContentBody.load("/category/list");
				} else {
					toastr.warning(result.msg);
				}
			}, "json");
		}
	});
});

 

</script>
